package com.create.rdjc.util;


import org.apache.velocity.Template;
import org.apache.velocity.VelocityContext;
import org.apache.velocity.app.VelocityEngine;

import java.io.StringWriter;
import java.util.Properties;

public class TempUtils {


    private static VelocityEngine ve;

    public static void init(){
        ve = new VelocityEngine();
        Properties prop = new Properties();
        prop.put("file.resource.loader.class", "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader");
        ve.init(prop);

    }
    public static VelocityContext getContext(){
        return new VelocityContext();
    }

    public static String startVelocity(String tempPath, VelocityContext context){
        context.put("ExcelUtils", new ExcelUtils());
        Template t = ve.getTemplate(tempPath);
        StringWriter sw = new StringWriter();
        t.merge(context, sw);
      return sw.toString();

    }


}
